<?php

if (!isset($segments[2]) || ($segments[2] < 1 || $segments[2] > 93)) {
    include APPPATH . '404.php';
    die();
}
$bookSql = 'SELECT `book_name`,`volume` FROM `bukhari_books` WHERE `id`=\'' . $segments[2] . '\'';
$bookQ = $db->query($bookSql);
$bookName = $bookQ->fetchAll(PDO::FETCH_ASSOC);

$title = $bookName[0]['book_name'];
$volume = $bookName[0]['volume'];


$sql = 'SELECT * FROM  `bukhari`
    LEFT JOIN `bukhari_narrators` ON `bukhari`.`narrator` = `bukhari_narrators`.`narrator_id`
    WHERE `bukhari`.`book_id`=\'' . $segments[2] . '\'';
$query = $db->query($sql);

$results = $query->fetchAll(PDO::FETCH_ASSOC);

include './app/layout/header.php';
?>
<div class="section_w670">
    <h2><?php echo $title; ?></h2>
</div>
<div class="cleaner_h10"></div>
<div class="section_w670">
<?php
foreach ($results as $result) {
    echo '<p><b>Hadith Number: ' . $result['hadith_number'] . ' Volume: ' . $volume . '</b><br />';
    echo '<b>Narrated By: ' . $result['narrator_name'] . '</b><br />';
    //echo '<div class="cleaner_h10"></div>';
    echo '' . $result['full_text'] . '</p>';
    echo '<div class="cleaner_h20"></div>';
}
?>
</div>
<div class="cleaner_h10"></div>
<?php
include './app/layout/footer.php';